{% extends "base.html" %}
{% load humanize %}
{% load widget_tweaks %}

{% block title %}
VulnerableCode Vulnerability Search
{% endblock %}

{% block content %}
<section class="section pt-0">
    {% include "vulnerability_search_box.html" %}
</section>

{% if search %}
    <div class="is-max-desktop mb-3">
        <section class="mx-5">
            <div class="is-flex" style="justify-content: space-between;">
                <div>
                    {{ page_obj.paginator.count|intcomma }} results
                </div>
              {% if is_paginated %}
                {% include 'includes/pagination.html' with page_obj=page_obj %}
              {% endif %}
            </div>
        </section>
    </div>

    <section class="section pt-0">
        <div class="content">
            <table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
                <thead>
                    <tr>
                        <th>Vulnerability id</th>
                        <th style="width: 225px;">Aliases</th>
                        <th style="width: 225px;"><span class="affected-fixed">Affected</span> packages</th>
                        <th style="width: 225px;"><span class="affected-fixed">Fixed by</span> packages</th>
                    </tr>
                </thead>
                <tbody>
                    {% for vulnerability in page_obj %}
                        <tr class="is-clipped-list">
                            <td style="word-break: break-all;">
                                <a
                                    href="{{ vulnerability.get_absolute_url }}?search={{ search }}"
                                    target="_self">{{ vulnerability.vulnerability_id }}
                                </a>
                            </td>
                            <td>
                                {% for alias in vulnerability.alias %}
                                    {% if alias.url %}
                                        <a href="{{ alias.url }}" target="_blank">{{ alias }}
                                            <i class="fa fa-external-link fa_link_custom"></i>
                                        </a>
                                    {% else %}
                                        {{ alias }}
                                    {% endif %}
                                    <br />
                                {% endfor %}
                            </td>
                            <td>{{ vulnerability.vulnerable_package_count }}</td>
                            <td>{{ vulnerability.patched_package_count }}</td>
                        </tr>
                    {% empty %}
                        <tr class="is-clipped-list">
                            <td colspan="3" style="word-break: break-all;">
                            No vulnerability found.
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>


      {% if is_paginated %}
        {% include 'includes/pagination.html' with page_obj=page_obj %}
      {% endif %}
    </section>
{% endif %}

{% endblock %}
